Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESLint rule to validate css props are declared before{...spread} props #6257

Merged
merged 7 commits into from
Sep 28, 2022
Merged

ESLint rule to validate css props are declared before{...spread} props #6257

merged 7 commits into from
Sep 28, 2022

Conversation

1Copenut
Copy link
Contributor

@1Copenut 1Copenut commented Sep 21, 2022

Summary

Adding an ESLint rule to validate css={cssProps} are added before {...rest} spread props in our EUI components.

Here's a neat screen shot showing the test running against unit tests. Each unit test was derived from an actual failure while linting locally.


Screen Shot 2022-09-27 at 1 36 32 PM

@1Copenut 1Copenut self-assigned this Sep 21, 2022
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6257/

@1Copenut 1Copenut added skip-changelog work in progress testing Issues or PRs that only affect tests - will not need changelog entries labels Sep 23, 2022
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6257/

…ing."

* Updating unit tests to pass before renaming.
* Registering ESLint rule locally before adding unit tests.
* Switched to JSXElement, and array of arrays.
* Simplified logic, added unit tests, fixed failures.
@1Copenut 1Copenut requested a review from cee-chen September 27, 2022 18:35
Copy link
Contributor Author

@1Copenut 1Copenut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All unit tests passing, no local lint failures. Moving out of WIP.

return {
JSXElement(node) {
const tempArr = [];
node.openingElement.attributes.forEach(attribute => tempArr.push(attribute));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@constancecchen Your comment about making an array of arrays was spot on. It took a few iterations, but I found good results removing all extra logic and running our previous checks against each array in turn.

},
];

const invalid = [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each invalid block was built out from real failures in EUI components, or derived therefrom.

@1Copenut 1Copenut changed the title WIP. First pass at CSS before spread child props ESLint rule. ESLint rule to validate css props are declared before{...spread} props Sep 27, 2022
@1Copenut 1Copenut marked this pull request as ready for review September 27, 2022 18:43
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6257/

@1Copenut
Copy link
Contributor Author

I'll look over the components with linting changes for visual regression. LMK if this feels like a breaking change and I'll add the label.

@cee-chen
Copy link
Contributor

cee-chen commented Sep 28, 2022

This looks and works great. I just have a couple very minor comments, fantastic work on this Trevor!

edit to add: this is not a breaking change, just IMO, and I agree it doesn't need a changelog

@1Copenut 1Copenut requested a review from cee-chen September 28, 2022 19:14
@1Copenut
Copy link
Contributor Author

Thank you @constancecchen for the 💯 code change suggestions. I turned on Prettier format on save, so it broke some of my one line const declarations into 2-3 and wrapped single arrow function arguments.

I esp liked the suggestion to move early return guard clauses closer to their declarations. Moving those lines around provided clearer intent.

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6257/

Copy link
Contributor

@cee-chen cee-chen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely!! 🎉

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6257/

@1Copenut 1Copenut merged commit 9d75128 into elastic:main Sep 28, 2022
@1Copenut 1Copenut deleted the feature/eslint-emotion-css branch September 28, 2022 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip-changelog testing Issues or PRs that only affect tests - will not need changelog entries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants